package com.zwj.batch.core.batch.job;

import com.zwj.batch.core.batch.step.UserStep;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 张文接
 * @version 1.0
 * @createTime 2023-06-26 11:25:00
 */
@Component
public class UserJob {
    @Resource
    private JobBuilderFactory jobBuilderFactory;
    @Resource
    private UserStep userStep;

    public Job getReadUserTxtJob() {
        return jobBuilderFactory.get("flat-reader-job1")
                .start(userStep.readUserTxtStep())
                .build();
    }

    public Job getReadUserTxtJob2() {
        return jobBuilderFactory.get("flat-reader-job2")
                .start(userStep.readUserTxtStep2())
                .build();
    }

    public Job getReadUserJsonJob() {
        return jobBuilderFactory.get("json-flat-reader-job")
                .start(userStep.readUserJsonStep())
                .build();
    }

    public Job getReadUserJsonValidateJob() {
        return jobBuilderFactory.get("validate-processor-job")
                .start(userStep.readUserJsonValidateStep())
                .build();
    }

    public Job getProcessUserJob() {
        return jobBuilderFactory.get("adapter-processor-job")
                .start(userStep.getProcessUserStep())
                .build();
    }

    public Job getCompositeProcessUserJob() {
        return jobBuilderFactory.get("composite-processor-job")
                .start(userStep.getCompositeProcessUserStep())
                .build();
    }

    public Job getCustomizeProcessUserJob() {
        return jobBuilderFactory.get("customize-processor-job")
                .start(userStep.getCustomizeProcessUserStep())
                .build();
    }

    /**
     * 学习batchJob用法的流程
     * @return Job
     */
    public Job batchJobStudy() {
        return jobBuilderFactory.get("batchJobStudyJob")
                .start(userStep.batchJobStudy())
                .build();
    }
}
